Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-127111: Emscripten Make web example work again #127113

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hoodmane
Copy link
Contributor

@hoodmane hoodmane commented Nov 21, 2024

I moved the web example from Tools/wasm into Tools/wasm/emscripten/web_example. I also added a new target build_emscripten which is build_wasm but also builds the web_example. The web_example needs:

  1. python.html, copied
  2. python.worker.mjs copied
  3. python.mjs and python.wasm output from the main linking of the Python interpreter
  4. The webserver that sets COOP and COEP
  5. python3.14.zip

This last is created by the wasm_assets.py script, which required a pretty small set of changes to work fine for us.

The last thing that should be done is the python.worker.mjs script should be made independent of the Python version: currently 3.14 is hard coded. I ran into trouble doing this, so maybe I can leave it to a followup.

Comment on lines -17 to -22
extensions_map = server.SimpleHTTPRequestHandler.extensions_map.copy()
extensions_map.update(
{
".wasm": "application/wasm",
}
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now the default behavior of SimpleHTTPRequestHandler.

@@ -2321,14 +2325,14 @@ AS_CASE([$ac_sys_system],
AS_VAR_IF([Py_DEBUG], [yes], [wasm_debug=yes], [wasm_debug=no])

dnl Start with 20 MB and allow to grow
AS_VAR_APPEND([LDFLAGS_NODIST], [" -sALLOW_MEMORY_GROWTH -sTOTAL_MEMORY=20971520"])
AS_VAR_APPEND([LDFLAGS_NODIST], [" -sALLOW_MEMORY_GROWTH -sINITIAL_MEMORY=20971520"])
Copy link
Contributor Author

@hoodmane hoodmane Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This setting has changed names. It's not really relevant to this PR, I could separate it into a separate NFC commit.

dnl map int64_t and uint64_t to JS bigint
AS_VAR_APPEND([LDFLAGS_NODIST], [" -sWASM_BIGINT"])
dnl Include file system support
AS_VAR_APPEND([LDFLAGS_NODIST], [" -sFORCE_FILESYSTEM -lidbfs.js -lnodefs.js -lproxyfs.js -lworkerfs.js"])
AS_VAR_APPEND([LDFLAGS_NODIST], [" -sEXPORTED_RUNTIME_METHODS=FS"])
AS_VAR_APPEND([LDFLAGS_NODIST], [" -sEXPORTED_RUNTIME_METHODS=FS,callMain"])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use callMain in python.worker.mjs now so we need to ask for it to be exported.

@@ -2339,7 +2343,6 @@ AS_CASE([$ac_sys_system],
AS_VAR_APPEND([LDFLAGS_NODIST], [" -sUSE_PTHREADS"])
AS_VAR_APPEND([LINKFORSHARED], [" -sPROXY_TO_PTHREAD"])
])
AS_VAR_APPEND([LDFLAGS_NODIST], [" -sALLOW_MEMORY_GROWTH"])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also set this on line 2328. It's harmless but unnecessary to set it twice.

I moved the web example from `Tools/wasm` into `Tools/wasm/emscripten/web_example`.
I also added a new target `build_emscripten` which is `build_wasm` but also
builds the web_example. The web_example needs:
1. python.html, copied
2. python.worker.mjs copied
3. python.mjs and python.wasm output from the main linking of the Python interpreter
4. The webserver that sets COOP and COEP
5. python3.14.zip

This last is created by the `wasm_assets.py` script, which required a pretty
small set of changes to work fine for us.

The last thing that should be done is the `python.worker.mjs` script should be
made independent of the Python version: currently 3.14 is hard coded. I ran
into trouble doing this, so maybe I can leave it to a followup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review build The build process and cross-build OS-emscripten
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant